<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../../lib/innerIframe-include-ext.js"></script>
<script type="text/javascript" src="../../lib/loader-theme.js"></script>
<script type="text/javascript" src="../../lib/ext/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../lib/ext/plugins/DataTip.js"></script>
<title>消息管理</title>
</head>
<script type="text/javascript">
Ext.require(['*']);
Ext.onReady(function(){
	Ext.QuickTips.init();
    Ext.define('webuser', {
        extend: 'Ext.data.Model',
        fields: [
            'student_id','student_name','openid'
        ],
        idProperty: 'student_id'
    });
	
    var store = Ext.create('Ext.data.Store', {
        pageSize: 10,
        model: 'webuser',
        remoteSort: true,
        proxy: {
            type: 'ajax',
            method: 'GET',
            url: '/student/get_admin_group',
            reader: {
                type: 'json',
                root: 'data',
                totalProperty: 'count'
            },
            simpleSortMode: true
        },
        sorters: [
            {
                property: 'student_name'
            }
        ]
    });
    
    var grid = Ext.create('Ext.grid.Panel', {
        id:'my_grid',
        store: store,
        loadMask: true,
        region: 'center',
        selModel: Ext.create('Ext.selection.CheckboxModel'),
        columns: [
        	{
        		text: '学生ID',
        		dataIndex: 'student_id',
        		hidden: true
        	},{
                text: "学生姓名",
                dataIndex: 'student_name',
                hidden: false
            },{
            	text: '微信ID',
            	dataIndex: 'openid',
            	hidden: true
            }
        ],
        bbar: Ext.create('Ext.PagingToolbar', {
            store: store,
            displayInfo: true,
            displayMsg: '当前显示  {0} - {1} 共  {2} 条',
            emptyMsg: "没有数据显示！",
            beforePageText: "页码",
			afterPageText: "共 {0} 页",
			firstText:"首页",
			lastText:"末页",
			nextText:"下一页",
			prevText:"上一页",
			refreshText:"刷新"
        }),
        tbar: [
			{
			    pressed: false,
			    icon : '../../img/add.png',
			    text: "创建消息",
			    disable:false,
			    handler: addHandler
			}]
    });
    store.loadPage(1);
	
	var viewport = Ext.create('Ext.Viewport', {
        id: 'border-example',
        layout: 'fit',
        items: grid
    });
	
	var addWin;
    var form;
    form = new Ext.FormPanel({
		id: 'myForm',
		url:'/msg/add',
    	method:'POST',
    	frame:true,
    	style:'border-width:0 0 0 0;',
    	bodyBorder:false,
    	bodyPadding: '0 20 0 0',
    	layout: 'form',
        plugins: {
            ptype: 'datatip'
        },
	    items: [
	    	{
	    		xtype: 'textfield',
	    		hidden: true,
	    		name: 'serialized_openid',
	    		id: 'serialized_openid'
	    	},{
				xtype:'textareafield',
				fieldLabel:'请输入消息:',
				name:'msg_text',
				labelAlign: 'right',
				maxLength:10000,
				allowBlank:false,
				tooltip:'请输入要发送消息',
				id:'msg_text',
                width: 400,
                height: 100
			}
	    ],
	    buttons:[{ 
    		text:'发  送',
    		icon:'../../img/accept.png',
    		handler:function(){
    			if(!form.getForm().isValid()){
    				 Ext.Msg.alert('信息提示','请检查输入项是否按要求填写！');
    				 return;
                }
                form.form.submit({
                	waitMsg:'正在保存数据...',
                	success:function(form,action){
                		if(action.result.success){
                			Ext.Msg.alert('信息提示',action.result.msg,function(){
                                store.reload();
                                Ext.getCmp('myForm').getForm().reset();
                                addWin.close();
                            });
                		} else {
                			Ext.Msg.alert('信息提示',action.result.msg);
                		}
                	},
                	failure:function(form,action){
                		Ext.Msg.alert('信息提示', action.result.msg);
                	}
                });
    		}
    	},{
    		text:'关  闭',
    		icon:'../../img/close.png',
    		handler:function(){
    			this.up('form').getForm().reset();
    			addWin.close();
    		}
    	}]
	});
    
    function addHandler(){
    	var records = grid.getSelectionModel().getSelection();
        if(records.length == 0){
            Ext.Msg.alert("信息提示","至少选择一个学生发送消息");
            return;
        } 
    	if(!addWin){
            addWin = Ext.create('Ext.window.Window', {
                title: '创建消息',
                width: 300,
                height: 200,
                //bodyPadding: '0 0 0',
                //'z-index': 9999999,
                constrainHeader: true,
                layout: 'fit',
                closeAction:'hide',
                items: form
            });
    	}
    	var serialized_openid = records.toJSONString();
    	form.form.loadRecord({'serialized_openid': serialized_openid, 'msg_text': ''});
    	//form.getForm().url='/dept/add';
    	addWin.show();
    }
});
</script>
<body>
</body>
</html>